/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
using System;
using UnitedBinary.UnitTests.Framework;

namespace UnitedBinary.HarnessIt.UnitTests.TestingTestClasses
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[TestClass("A test class for testing various behaviors of HarnessIt's running and testing.")]
	public class TestClass
	{
		public TestClass()
		{
		}

		[TestMethod("A series of successful tests.")]
		public void GoodTests(TestMethodRecord tmr)
		{
			for (int i=0; i<12; i++)
                tmr.RunTest(true, "Good test " + (i+1));
		}

		[TestMethod("A series of good and/or bad tests.")]
		public void TheGoodAndTheBadTests(TestMethodRecord tmr)
		{
			Random rnd = new Random();
			for (int i=0; i < 20; i++)
			{
				tmr.RunTest(rnd.Next(0, 2) == 1, "A good or bad test.");
			}
			System.Threading.Thread.Sleep(400);
		}

		[TestMethod("Throw an unhandled exception, should fail.")]
		public void CompletelyUnhandledException(TestMethodRecord tmr)
		{
			// Just to see the detailed report, I'll make it complicated:
			Exception inner = new System.ArgumentNullException("parameter name", "Null argument message.");
			System.Exception e = new Exception("Top level regular msg.", inner);

			throw e;
		}

		[TestMethod("Test excepted exception catching (success).")]
		public void ExpectedExceptionSuccess(TestMethodRecord tmr)
		{
			tmr.RegisterException("This should throw an exception.");
			throw new ArgumentNullException("buffer[0]","a test null exception.");
		}

		[TestMethod("Test excepted exception catching (fail).")]
		public void ExpectedExceptionFail(TestMethodRecord tmr)
		{
			Exception inner = new System.ArgumentNullException("theta", "Null argument message.");
			System.ArgumentException e = new ArgumentException("Mid-level ArgumentException msg.", "angles[i]", inner);
			System.IO.FileNotFoundException f = new System.IO.FileNotFoundException("Top-level file not found exception.", e);

			tmr.RegisterException("This will throw an exception, but the wrong type.", typeof(System.ArgumentOutOfRangeException));
			throw f;
		}

		[TestMethod("Exception Test")]
		public void ExceptionTypeTest1(TestMethodRecord tmr)
		{
			tmr.RegisterException("Expected exception thrown", typeof(Exception));
			throw new Exception();
		}

		[TestMethod("Exception Test")]
		public void ExceptionTypeTest_Consistent(TestMethodRecord tmr)
		{
			tmr.RegisterException("Expected exception not thrown", typeof(ArgumentNullException));
			throw new ArgumentNullException("Just a test");
		}

		[TestMethod("Exception Test")]
		public void ExceptionTypeTest_Inconsistent(TestMethodRecord tmr)
		{
			tmr.RegisterException("Expected exception not thrown", typeof(System.IO.FileNotFoundException));
			throw new ArgumentNullException("Just a test");
		}
	}
}

